package com.suse.warmstill.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.suse.warmstill.common.model.CallResult;
import com.suse.warmstill.entity.TbCategory;
import com.suse.warmstill.mapper.TbCategoryMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author 黄靖
 * @author 2022-11-03 20:51
 * description:
 **/
@Api(tags = "wx的分类字典")
@RequestMapping("/WxData")
@RestController
public class WxDataApi {
    @Autowired
    private TbCategoryMapper categoryMapper;

    @ApiOperation("分类字典")
    @GetMapping("/category")
    public CallResult getCategoryData() {
        final List<TbCategory> categories = categoryMapper.selectList(new LambdaQueryWrapper<TbCategory>());
        final HashMap<Long, String> map = new HashMap<>();

        categories.forEach((category) -> {
            final Long id = category.getId();
            final String categoryName = category.getCategoryName();
            map.put(id, categoryName);
        });

        return CallResult.success(map);
    }


}
